let ExportService = require('./ExportService');
let utils = require('./../../utils/utils')

class RtcTaskService extends ExportService {
  initParam () {
    this.tableConfigs = [
      { tableName: 'users' }
    ]
    this.enumTypes = ['TASK_PRIORITY', 'TASK_IMPORTANT', 'ITEM_STATE']
    this.header = [
      { header: '序号', width: 5 },
      { header: '任务编码', width: 10 },
      { header: '任务标题', width: 26 },
      { header: '任务详情', width: 40 },
      { header: '开始时间', width: 15 },
      { header: '结束时间', width: 15 },
      { header: '优先级', width: 15 },
      { header: '重要性', width: 15 },
      { header: '执行人', width: 10 },
      { header: '状态', width: 15 },
      { header: '创建者', width: 10 },
      { header: '创建时间', width: 10 }
    ]
  }

  formateData (dataList) {
    return new Promise((resolve, reject) => {
      let rowDatas = []
      let data = {}
      for (let i = 0, len = dataList.length; i < len; i++) {
        data = dataList[i]
        rowDatas.push([
          i + 1,
          data.task_id,
          data.name,
          this.getSimpleText(data.summary),
          this.dateFormater(data.start_date, 'yyyy-MM-dd'),
          this.dateFormater(data.end_date, 'yyyy-MM-dd'),
          this.dataFormater('TASK_PRIORITY', data.priority, 'value', 'name'),
          this.dataFormater('TASK_IMPORTANT', data.important, 'value', 'name'),
          this.dataArrFormater('users', data.user_id, '_id', 'userName'),
          this.dataFormater('ITEM_STATE', data.state, 'value', 'name'),
          this.dataArrFormater('users', data.user_id, '_id', 'userName'),
          this.dateFormater(data.create_at, 'yyyy-MM-dd'),
          this.dataArrFormater('users', data.create_user, '_id', 'userName')
        ])
      }
      resolve(rowDatas)
    })
  }

  //html剔除富文本标签，留下纯文本
  getSimpleText (html) {
    let result = ''
    if (html) {
      var re1 = new RegExp("<.+?>","g");//匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
      result = html.replace(re1,'');//执行替换成空字符
    }
    return result;
  }
}

module.exports = new RtcTaskService()